/********************************************************************
	file base:	ExtractDlg
	file ext:	h
	author:		JiangHuai
	
	purpose:	Extract Dlg procedure
*********************************************************************/

#ifndef EXTRACT_DLG
#define EXTRACT_DLG

#include "resource.h"

INT CALLBACK ExtractDialogProc(
							HWND hwndDlg,
							UINT uMsg,
							WPARAM wParam,
							LPARAM lParam
							) {

	switch (uMsg)
	{
	case WM_COMMAND:

		switch (LOWORD(wParam))
		{
		case IDC_IMAGE_BROWSER:
			ofn.hwndOwner = hwndDlg;
			if (GetOpenFileName(&ofn)) {
				SetDlgItemText(hwndDlg, IDC_FILEPATH, (LPCTSTR)OpenFileName);
			}
			break;
		case IDCANCEL:
			EndDialog(hwndDlg, 0);
			break;
		case IDC_FILEPATH:
			GetDlgItemText(hwndDlg, IDC_FILEPATH, (LPSTR)&OpenFileName, MAX_LENGTH);
			break;
		case ID_EXTRACT:
			if (!string((char*)OpenFileName).empty()) {
				info.fileType = getFormat(OpenFileName);
				info.embed.Load((const TCHAR*)&OpenFileName, info.fileType);
			}
			WCHAR key[MAX_LENGTH];
			int status = GetDlgItemText(hwndDlg, IDC_KEY, (LPSTR)&key, MAX_LENGTH);
			if (status != 0) {
				info.key = string((char*)key);
			} else info.key = "";
			Extract();

			SetDlgItemText(hwndDlg, IDC_EMBED_PLAIN_TEXT, (LPCTSTR)info.plainText.c_str());
			break;
		}
		break;

	}
	return 0;
}

#endif